#include <linux/unistd.h>
#include <sys/syscall.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void initializeList(void);
void insert_white_list(unsigned int d);
int white_listed(unsigned int d);

typedef struct {
  unsigned int data;
} dataInfo;

typedef struct ListNode {
  dataInfo d_info;
  struct ListNode * next;
} ListNodeType;

typedef ListNodeType * ListNodePtrType;
ListNodePtrType front, listPtr;

void initializeList() {
  front = NULL;
  listPtr = (ListNodePtrType) malloc (sizeof(ListNodeType));
}

void insert_white_list(unsigned int d) {  
  ListNodePtrType temp;
  temp = (ListNodePtrType) malloc (sizeof(ListNodeType));
  temp->d_info.data = d;    

  if (front == NULL) {
    front = temp;
    front->next = NULL;
  }
  else {
    listPtr = front;
    while (listPtr->next != NULL) {
      listPtr = listPtr->next;
    }
    temp->next = listPtr->next;
    listPtr->next = temp;
  }
}

int white_listed(unsigned int d) {
  if (front == NULL) return 0;
  listPtr = front;
  
  while ((listPtr != NULL)) {
    if (listPtr->d_info.data == d) return 1;
    listPtr = listPtr->next;
  }
  return 0;
}
